var salt = sessionStorage.getItem('usersalt');

layui.use(['form', 'layer'], function() {
	var form = layui.form,
		layer = parent.layer === undefined ? layui.layer : top.layer,
		$ = layui.jquery;

	if(!sessionStorage.getItem('username')) {
		layer.msg('请先登录');
		setTimeout("top.location.href='../../../index.html'", 1000);
	}
});

var info = "";
var itemArrDanger = [];
var itemArrEvent = [];
var itemArrRisk = [];
var list = [];
//获取详情
var checkId = getQueryVariable("id");
console.log(checkId)
if(checkId != false) {
	$.ajax({
		url: url + '/dangerList/getInfo',
		dataType: 'json',
		async: false,
		type: "POST",
		data: {
			Token: salt,
			id: checkId,
			type: 1
		},
		success: function(data) {
			if(data.code == 0) {
				console.log(data.data.type);
				if(data.data.type == 0) {
					$("#typeName").html(data.data.typeName);
					$("#name").html(data.data.name);
					$("#seat").html(data.data.seat);
					$("#numberNo").html(data.data.numberNo);
					$("#entId").html(data.data.entName);
					if(data.data.attId !=null){
						
					
					var str = '<img onclick="lookbigpic(\'' + data.data.attId + '\')" src="' + url + 'attachment/seekFile/' + data.data.attId + '" width="100px" height="100px" class="picsty">';
					$("#attId").html(str);
					}
					
					itemArrDanger = JSON.parse(data.data.danger);
					itemArrEvent = JSON.parse(data.data.event);
					itemArrRisk = JSON.parse(data.data.risk);
					list = itemArrDanger;
					if(itemArrEvent.length > itemArrDanger.length) {
						list = itemArrEvent;
					}
					if(itemArrRisk.length > itemArrEvent.length) {
						list = itemArrRisk;
					}
					initItemDangerShow();
				}
				if(data.data.type == 1) {
					document.getElementById("indextype02").style.display = "";
					$("#errname").html(data.data.name);
					$("#errseat").html(data.data.seat);
					$("#errtypeName").html(data.data.typeName);
					$("#errentName").html(data.data.entName);
					$("#errstaff").html(data.data.staff);

					$("#errnumberNo").html(data.data.numberNo);
					$("#errfeatures").html(data.data.features);
					$("#errcontent").html(data.data.content);
					$("#errfrequencyId").html(data.data.frequencyId);
					$("#errremarks").html(data.data.remarks);
				}
				if(data.data.type == 2) {
					document.getElementById("indextype03").style.display = "";
					$("#entName").html(data.data.entName);
					$("#elseat").html(data.data.seat);
					var itemArr = JSON.parse(data.data.risk);
					var tbodyHtml = "";

					for(var i = 0; i < itemArr.length; i++) {
						var contentHtml = "";
						contentHtml =
							"<tr>" +
							"<th>" +
							"<div class=\"layui-table-cell laytable-cell-1-0\" align=\"center\"><span>" + itemArr[i].factor + "</span></div>" +
							"</th>" +
							"<th>" +
							"<div class=\"layui-table-cell laytable-cell-1-1\" align=\"center\"><span>" + itemArr[i].shape + "</span></div>" +
							"</th>" +
							"<th>" +
							"<div class=\"layui-table-cell laytable-cell-1-2\" align=\"center\"><span>" + itemArr[i].task + "</span></div>" +
							"</th>" +
							"<th>" +
							"<div class=\"layui-table-cell laytable-cell-1-3\" align=\"center\"><span>" + itemArr[i].staff + "</span></div>" +
							"</th>" +
							"<th>" +
							"<div class=\"layui-table-cell laytable-cell-1-3\" align=\"center\"><span>" + itemArr[i].remarks + "</span></div>" +
							"</th>" +
							"</tr>";
						tbodyHtml += contentHtml;
					}

					$("#eltable").html(tbodyHtml);
				} else {
					layer.msg(data.msg);
				}
			}
		},
		error: function(error) {
			console.log("获取失败");
		}
	});
} else {
	setTimeout(function() {
		layer.msg("详情id为空");
		setTimeout(function() {
			History.go(-1);
		}, 1000);
	}, 1000);
}

//危险介质信息
function initItemDangerShow() {
	document.getElementById("indextype01").style.display = "";
	var tbodyHtml = "";
	var rightTab = 1; //右侧添加按钮行数
	for(var i = 0; i < list.length; i++) {
		var contentHtml = "";
		var itemArrDangerHtml = "";
		var itemArrEventHtml = "";
		var itemArrRiskHtml = "";
		if(itemArrDanger.length > i) {
			itemArrDangerHtml =
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-0\" align=\"center\"><span>" + itemArrDanger[i].danger + "</span></div>" +
				"</th>" +
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-1\" align=\"center\"><span>" + itemArrDanger[i].temperature + "</span></div>" +
				"</th>";
		} else {
			itemArrDangerHtml =
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-0\" align=\"center\"><span></span></div>" +
				"</th>" +
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-1\" align=\"center\"><span></span></div>" +
				"</th>";
		};

		if(itemArrEvent.length > i) {
			itemArrEventHtml =
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-2\" align=\"center\"><span>" + itemArrEvent[i].content + "</span></div>" +
				"</th>" +
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-3\" align=\"center\"><span>" + itemArrEvent[i].frequency + "</span></div>" +
				"</th>" +
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-3\" align=\"center\"><span>" + itemArrEvent[i].staff + "</span></div>" +
				"</th>";
		} else {
			itemArrEventHtml =
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-2\" align=\"center\"><span></span></div>" +
				"</th>" +
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-3\" align=\"center\"><span></span></div>" +
				"</th>" +
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-3\" align=\"center\"><span></span></div>" +
				"</th>";
		};

		if(itemArrRisk.length > i) {
			itemArrRiskHtml =
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-4\" align=\"center\"><span>" + itemArrRisk[i].risk + "</span></div>" +
				"</th>" +
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-5\" align=\"center\"><span>" + itemArrRisk[i].factor + "</span></div>" +
				"</th>" +
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-4\" align=\"center\"><span>" + itemArrRisk[i].remarks + "</span></div>" +
				"</th>";
		} else {
			itemArrRiskHtml =
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-4\" align=\"center\"><span></span></div>" +
				"</th>" +
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-5\" align=\"center\"><span></span></div>" +
				"</th>" +
				"<th>" +
				"<div class=\"layui-table-cell laytable-cell-1-4\" align=\"center\"><span></span></div>" +
				"</th>";
		};

		contentHtml += "<tr>" + itemArrDangerHtml + itemArrEventHtml + itemArrRiskHtml + "</tr>";

		tbodyHtml += contentHtml;
	};
	$("#addTable").html(tbodyHtml);
}

//导出PDF
$(".export_btn").click(function() {

	$.post(url + 'dangerList/exportInfo', {
				Token: salt,
				id: checkId
			}, function(result) {
				window.open(url + "file" + result.data);
			});
});

function lookbigpic(self) {
	console.log(self);
	var json = {
		"status": 1,
		"msg": "",
		"title": "",
		"id": 8,
		"start": 0,
		"data": [{
			"alt": "",
			"pid": 109,
			"src": url + "attachment/seekFile/" + self,
			"thumb": ""
		}]
	}
	layer.photos({
		photos: json,
		anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
	});

}